package ru.spb.osll.myfit.common;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Vector;

import org.junit.Test;

import ru.spb.osll.myfit.server.parser.PageParser;
import ru.spb.osll.myfit.server.parser.PageParserUtils;

public class TableTest {

	private final String TEST_TABLE = new String("|Mul|" + PageParser.LINE_SEPARATOR
			+ "|multiplicand|multiplier|result?|"+ PageParser.LINE_SEPARATOR + "|2|4|8|" + PageParser.LINE_SEPARATOR);

	Table table = new Table(TableStyle.UNKNOWN_FIXTURE);

	@Test
	public void testIsEmpty() {
		assertTrue(table.isEmpty());
	}

	@Test
	public void testAddLine() {
		TableCell string = new TableCell("test");
		Vector<TableCell> line = new Vector<TableCell>();
		line.add(string);
		table.addLine(line);
		assertFalse(table.isEmpty());
	}

	@Test
	public void testClear() {
		table.clear();
		assertTrue(table.isEmpty());
	}

	@Test
	public void testToString() {
		Table table = new Table(TableStyle.COLUMN_FIXTURE);
		Vector<TableCell> line = new Vector<TableCell>();
		line.add(new TableCell("Mul"));
		table.addLine(line);
		line = new Vector<TableCell>();
		line.add(new TableCell("multiplicand"));
		line.add(new TableCell("multiplier"));
		line.add(new TableCell("result?"));
		table.addLine(line);
		line = new Vector<TableCell>();
		line.add(new TableCell("2"));
		line.add(new TableCell("4"));
		line.add(new TableCell("8"));
		table.addLine(line);

		assertEquals(TEST_TABLE, PageParserUtils.tableToString(table));
	}

}
